import axios from "axios";
import { cdadList } from "./data";

const service = axios.create({
  timeout: 15000 // 请求超时时间
});
// import {departs, doctors,hospitals} from "../data";
// service.defaults.baseURL = 'https://api.example.com';
service.defaults.baseURL = 'http://47.98.143.6:8888/';
// service.defaults.headers.common['Authorization'] = AUTH_TOKEN;
// service.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
service.defaults.headers.post['Content-Type'] = 'application/json';
service.defaults.responseType = 'json';
// 添加请求拦截器
service.interceptors.request.use(config => {
    // 在发送请求之前做些什么
    return config;
}, error => {
    // 对请求错误做些什么
    return Promise.reject(error);
});

// 添加响应拦截器
service.interceptors.response.use(response => {
    // 对响应数据做点什么
    response.data = response.request.response;
    return response;
}, error => {
    // 对响应错误做点什么
    return Promise.reject(error);
});


const getDoctor = (id: string) => {
    return service.get("/doctors/");
};

const getDepart = (params: any) => {
    return service.get("/departs/", {
        params:{...params.payload}
    });
};

const getPatient = (params: any) => {
  // return instance.post("/queryDepartmentGroupByFirstClass",{
  //     params:{...params}
  // });
    return service.get("/medicalcards", {
        params
    })
};


const getHospital = (params: object) => {
    return service.get("/hospitals/", {
        params
    });
};

const appointmentConfirm = (params: object) => {
    return service.post("/confirm", {params});
};

const getMedicalCard = (params: object) => {
    return service.get("/medicalcards", {
        params
    })
};

const deleteMedicalCard = (id: object) => {
    return service.delete("/medicalcards/" + id)
};

const updateMedicalCard = (card: object) => {
    return service.patch("/medicalcards", {
        params: card
    })
};

const addMedicalCard = (card:object)=>{
    return service.post("/medicalcards/",{
        params:card
    });
};

export {
    appointmentConfirm,
    addMedicalCard,
    updateMedicalCard,
    deleteMedicalCard,
    getMedicalCard,
    getDoctor,
    getDepart,
    getHospital,
    getPatient,
}
